import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class TestSuite {
	

    booleanSchedule student1 = new booleanSchedule();
    booleanSchedule adviser1 = new booleanSchedule();
    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception {
            booleanSchedule student1 = new booleanSchedule();
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception {
            student1 = null;
    }
    
    @Test
    public void  initializeBooleanScheduleTest()
    {

            
            Assert.assertFalse(student1.getAvailable(0));
            Assert.assertFalse(student1.getAvailable(55));
    }
    

    
    @Test
    public void  checkSetMeetTime()
    {
            milTimeSchedule timeSchedule;
            
            timeSchedule = new milTimeSchedule();
            
            timeSchedule.setMinimumMeetTime(4);
            
            Assert.assertEquals(4,timeSchedule.getMeetTime());
            
    }
    @Test
    public void  compareSchedules(){
            milTimeSchedule student = new milTimeSchedule();
            milTimeSchedule adviser = new milTimeSchedule();
            student.setAvailable(800, 830);
            student.setAvailable(915, 1000);
            student1.generateSchedule(student);
            
            adviser.setAvailable(800, 900);
            adviser.setAvailable(930, 1000);
            adviser1.generateSchedule(adviser);
            // they should overlap at 800-830
            booleanSchedule resultSchedule = new booleanSchedule();
            for (int count=0; count<56; count++){
                    if(student1.getAvailable(count) == true && adviser1.getAvailable(count)==true){
                            resultSchedule.setAvailable(count);
                    }                       
            }
            //915 and 1000 should be false, 930 945 should be true
            Assert.assertFalse(resultSchedule.getAvailable(5));
            Assert.assertTrue(resultSchedule.getAvailable(6));
            Assert.assertTrue(resultSchedule.getAvailable(7));
            Assert.assertFalse(resultSchedule.getAvailable(8));
            
    }
    @Test
    public void testBoolToMilSingleSlot(){
            milTimeSchedule mil = new milTimeSchedule();
            booleanSchedule original =  new booleanSchedule();
            original.setAvailable(2);
            original.setAvailable(3);
            original.setAvailable(4);
            original.setAvailable(5);
            
            mil = original.getMilTimeSchedule();
            
            Assert.assertEquals(830, mil.getStart(0));
            Assert.assertEquals(930, mil.getEnd(0));
    }
    
    @Test
    public void testBoolToMilTwoSlots(){
            milTimeSchedule mil = new milTimeSchedule();
            booleanSchedule original =  new booleanSchedule();
            original.setAvailable(2);
            original.setAvailable(3);
            original.setAvailable(4);
            original.setAvailable(5);
            
            original.setAvailable(15);
            original.setAvailable(16);
            original.setAvailable(17);
            
            
            mil = original.getMilTimeSchedule();
            
            Assert.assertEquals(830, mil.getStart(0));
            Assert.assertEquals(930, mil.getEnd(0));
            
            Assert.assertEquals(1145, mil.getStart(1));
            Assert.assertEquals(1230, mil.getEnd(1));

    }
    
    @Test
    public void testBoolToMilSingleSlotToEnd(){
            milTimeSchedule mil = new milTimeSchedule();
            booleanSchedule original =  new booleanSchedule();
            original.setAvailable(52);
            original.setAvailable(53);
            original.setAvailable(54);
            original.setAvailable(55);
            
            mil = original.getMilTimeSchedule();
            
            Assert.assertEquals(2100, mil.getStart(0));
            Assert.assertEquals(2200, mil.getEnd(0));

    }
    
    @Test
    public void testBoolToMilSingleSlotStartToEnd(){
            milTimeSchedule mil = new milTimeSchedule();
            booleanSchedule original =  new booleanSchedule();
            
            for(int all=0;all<56;all++)
            {
                    original.setAvailable(all);
            }
            
            mil = original.getMilTimeSchedule();
            
            Assert.assertEquals(800, mil.getStart(0));
            Assert.assertEquals(2200, mil.getEnd(0));

    }
    
    @Test
    public void testBoolToMilMultipleSlots(){
            milTimeSchedule mil = new milTimeSchedule();
            booleanSchedule original =  new booleanSchedule();
            
            for(int all=0;all<56;all++)
            {
                    original.setAvailable(all);
            }
            
            original.setUnavailable(10);
            original.setUnavailable(36);
            original.setUnavailable(44);
            
            mil = original.getMilTimeSchedule();
            
            Assert.assertEquals(800, mil.getStart(0));
            Assert.assertEquals(1030, mil.getEnd(0));
            
            Assert.assertEquals(1045, mil.getStart(1));
            Assert.assertEquals(1700, mil.getEnd(1));
            
            Assert.assertEquals(1715, mil.getStart(2));
            Assert.assertEquals(1900, mil.getEnd(2));
            
            Assert.assertEquals(1915, mil.getStart(3));
            Assert.assertEquals(2200, mil.getEnd(3));


    }
    @Test
    public void  checkAvailableScheduleTest()
    {
            milTimeSchedule timeSchedule;
            
            timeSchedule = new milTimeSchedule();
            timeSchedule.setAvailable(800, 845);
            timeSchedule.setAvailable(915,945);
            //800-830 means that boolSchedule[0,1] should be true and nothing else
            student1.generateSchedule(timeSchedule);
            
//          timeSchedule.setAvailable(900, 930);
//          student1.generateSchedule(timeSchedule);
            Assert.assertTrue(student1.getAvailable(0));
            Assert.assertFalse(student1.getAvailable(3));
            Assert.assertTrue(student1.getAvailable(5));
            Assert.assertTrue(student1.getAvailable(6));
            Assert.assertFalse(student1.getAvailable(7));
    }
    @Test
    public void testAllSlotsMatch()
    {
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule result = new booleanSchedule();
    	 for(int all=0;all<56;all++)
         {
                 student.setAvailable(all);
                 advisor.setAvailable(all);
                 if(student.getAvailable(all)==true && advisor.getAvailable(all)){
                	 result.setAvailable(all);
                 }
         }
    	 Assert.assertTrue(result.getAvailable(0));
    	 Assert.assertTrue(result.getAvailable(5));
    	 Assert.assertTrue(result.getAvailable(40));
    	 Assert.assertTrue(result.getAvailable(51));
    }
    @Test
    public void testTwoDifferentSlotsMatch()
    {
    	booleanSchedule student = new booleanSchedule();
    	booleanSchedule advisor = new booleanSchedule();
    	booleanSchedule result = new booleanSchedule();
    	
    	student.setAvailable(0);
    	student.setAvailable(1);
    	student.setAvailable(21);
    	student.setAvailable(22);
    	student.setAvailable(23);
    	student.setAvailable(24);
    	student.setAvailable(40);
    	student.setAvailable(41);

    	advisor.setAvailable(0);
    	advisor.setAvailable(1);
    	advisor.setAvailable(2);
    	advisor.setAvailable(3);
    	advisor.setAvailable(21);
    	advisor.setAvailable(22);
    	advisor.setAvailable(40);
    	advisor.setAvailable(41);
    	
    	for(int i=0;i<56;i++){
    		if(student.getAvailable(i)==true && advisor.getAvailable(i)==true){
    			result.setAvailable(i);
    		}
    	}
    	Assert.assertTrue(result.getAvailable(0));
   	 	Assert.assertTrue(result.getAvailable(1));
   	 	Assert.assertTrue(result.getAvailable(21));
   	 	Assert.assertTrue(result.getAvailable(22));
   	 	Assert.assertTrue(result.getAvailable(40));
   	 	Assert.assertFalse(result.getAvailable(23));
   	 	Assert.assertFalse(result.getAvailable(3));
   	 	Assert.assertFalse(result.getAvailable(33));
    }
    @Test
    public void testContraryTimeSlots(){
    	booleanSchedule b = new booleanSchedule();
    	b.setAvailable(4);
    	b.setAvailable(5);
    	b.setUnavailable(5);
    	b.setUnavailable(6);
    	milTimeSchedule m = b.getMilTimeSchedule(15);
    	Assert.assertFalse(b.getAvailable(5));
    	Assert.assertEquals(900, m.getStart(0));
    	Assert.assertEquals(915, m.getEnd(0));
    }
    @Test
    public void testSetMilTimeSchedUnavailable(){
    	booleanSchedule b = new booleanSchedule();
    	b.setAvailable(4);
    	b.setAvailable(5);
    	b.setAvailable(6);
    	b.setAvailable(7);
    	b.setAvailable(8);
    	b.setMilTimeSchedUnavailable(b.getMilTimeSchedule(),900, 945);
    	Assert.assertFalse(b.getAvailable(5));
    	Assert.assertFalse(b.getAvailable(6));
    	Assert.assertTrue(b.getAvailable(7));
    }
    @Test
    public void testMilScheduleToBoolScheduleMethod(){
    	milTimeSchedule m = new milTimeSchedule();
    	booleanSchedule b = new booleanSchedule();
    	
    	m.setAvailable(930, 1200);
    	m.setAvailable(1400, 1515);
    	m.setAvailable(1700, 2200);
    	
    	b = m.getBoolSchedule();
    	
    	Assert.assertTrue(b.getAvailable(11));
    	Assert.assertTrue(b.getAvailable(26));
    	Assert.assertTrue(b.getAvailable(47));
    	Assert.assertFalse(b.getAvailable(2));
    	Assert.assertFalse(b.getAvailable(18));
    	Assert.assertFalse(b.getAvailable(30));
    }
}
